﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace AndersLiu.EmailQueue
{
	/// <summary>
	/// 用于读取配置文件中的EmailQueue节。
	/// </summary>
	public class EmailQueueConfigSection : ConfigurationSection
	{
		/// <summary>
		/// 获取配置文件中的EmailQueue节。
		/// </summary>
		/// <returns></returns>
		public static EmailQueueConfigSection GetConfig()
		{
			return (EmailQueueConfigSection)ConfigurationManager.GetSection("EmailQueue");
		}

		/// <summary>
		/// 获取EmailQueue/ConnectionString配置。
		/// </summary>
		[ConfigurationProperty("ConnectionString", IsRequired = true)]
		public EmailQueueConnectionStringConfig ConnectionString
		{
			get { return (EmailQueueConnectionStringConfig)base["ConnectionString"]; }
		}
	}

	/// <summary>
	/// 表示EmailQueue/ConnectionString配置。
	/// </summary>
	public class EmailQueueConnectionStringConfig : ConfigurationElement
	{
		/// <summary>
		/// 获取EmailQueue/ConnectionString/Name配置。表示所使用的连接字符串的名字。
		/// </summary>
		[ConfigurationProperty("Name", IsRequired = true)]
		public string Name
		{
			get { return (string)base["Name"]; }
		}

		/// <summary>
		/// 获取实际的连接字符串内容。来自connectionStrings配置节，其名字由EmailQueue/ConnectionString/Name配置指定。
		/// </summary>
		public string ConnectionString
		{
			get { return ConfigurationManager.ConnectionStrings[Name].ConnectionString; }
		}
	}
}
